<?php
class SsoWS_Model_UserProperty extends Ext_Db_Table
{
	protected $_name = "sys_user_property";
	protected $_sequence = "sys_user_property_seq";
	protected $_primary = array( "user_id", "property" );
	
	public function save( $data ) 
	{		
		$validator = new Zend_Validate();
		$validator->addValidator(
			new Zend_Validate_StringLength(1, 50)
		);
		
		if( $validator->isValid( $data->property ) ) {
			if( $validator->isValid( $data->value ) ) {
				$row = $this->exist( $data );
				if( $row == false ){
					$row = $this->createRow();
					$row->user_id = $data->user_id;
					$row->property = $data->property;
				}
				$row->value = $data->value; 
				$row->save();
				return true;
			}
		}
		return false;
	}
	
	public function exist( $data )
	{	
		$row = $this->find( $data->user_id, $data->property )->current();
		if( count( $row )){
			return $row;
		}
		return false;
	}

}